<style>
    .letter-head {
        border-radius: 18px;
        padding-right: 12px;
        margin-left: 12px;
        margin-right: 12px;
    }

    .letter-head td{
        padding: 0px !important;
    }
    .invoice-header {
        width: 100%;
    }
    .logo-cell {
        width: 100px;
        text-align: center;
        position: relative;
    }
    .logo-container {
        width: 90px;
        display: block;
    }
    .logo-container img {
        max-width: 90px;
        max-height: 90px;
        display: inline-block;
        border-radius: 15px;
    }
    .company-details {
        width: 40%;
        align-content: center;
    }
    .company-name {
        font-size: 14px;
        font-weight: bold;
        color: #171717;
        margin-bottom: 4px;
    }
    .invoice-info-cell {
        float: right;
        vertical-align: top;
    }
    .invoice-info {
        margin-bottom: 2px;
    }
    .invoice-label {
        color: #7C7C7C;
        display: inline-block;
        width: 60px;
        margin-right: 5px;
    }
</style>

<table class="invoice-header">
    <tbody>
        <tr>
            <td class="logo-cell" style="vertical-align: middle !important;">
                <div class="logo-container">
                    {% set company_logo = frappe.db.get_value("Company", doc.company, "company_logo") %}
                    {% if company_logo %}
                        <img src="{{ frappe.utils.get_url(company_logo) }}" alt="Company Logo">
                    {% endif %}
                </div>
            </td>

            <td class="company-details">
                <div class="company-name">
                    {{ doc.company }}
                </div>
                {% if doc.company_address %}
                    {% set company_address = frappe.db.get_value("Address", doc.company_address, ["address_line1", "address_line2", "city", "state", "pincode", "country"], as_dict=True) %}

                    {{ company_address.get("address_line1") or "" }}<br>
                    {% if company_address.get("address_line2") %}{{ company_address.get("address_line2") }}<br>{% endif %}
                    {{ company_address.get("city") or "" }}, {{ company_address.get("state") or "" }} {{ company_address.get("pincode") or "" }}, {{ company_address.get("country") or "" }}<br>
                {% endif %}
            </td>

            <td class="invoice-info-cell">
                {% set company_details = frappe.db.get_value("Company", doc.company, ["website", "email", "phone_no"], as_dict=True) %}

                <div class="invoice-info">
                    <span class="invoice-label">{{ _("Invoice:") }}</span>
                    <span>{{ doc.name }}</span>
                </div>
                {% if company_details.website %}
                    <div class="invoice-info">
                        <span class="invoice-label">{{ _("Website:") }}</span>
                        <span>{{ company_details.website }}</span>
                    </div>
                {% endif %}
                {% if company_details.email %}
                    <div class="invoice-info">
                        <span class="invoice-label">{{ _("Email:") }}</span>
                        <span>{{ company_details.email }}</span>
                    </div>
                {% endif %}
                {% if company_details.phone_no %}
                    <div class="invoice-info">
                        <span class="invoice-label">{{ _("Contact:") }}</span>
                        <span>{{ company_details.phone_no }}</span>
                    </div>
                {% endif %}
            </td>
        </tr>
    </tbody>
</table>
